<?php

namespace app\common\model\Hotel;

use think\Model;

class Guest extends Model
{
    //
    protected $name = "hotel_guest";


    // 获取器
    protected $append = [
        'sex_text'
    ];


    // 性别
    public function getSexTextAttr($value,$data){
        $sexlist = [0 => '保密', 1 => '男', 2 => '女'];

        $sex = isset($data['sex']) ? $data['sex'] : '';

        if($sex >= '1'){
            return $sexlist[$sex];
        }
        return; 
    }


    
    public function business(){
        // record.busid = business.id
        // $this->belongsTo(关联外键模型，外键字段，关键表的主键,废弃的参数，链表方式)
        // setEagerlyType(0) 采用join的方式来查询
        return $this->belongsTo('app\common\model\Business\User','busid','id',[],'LEFT')->setEagerlyType(0);
    }
}
